package com.abhinav.designPatterns;

public class CloneDemo extends Object{

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Box b1 = new Box(10, 5, new Object());
		System.out.println(b1.area());
		Object obj = b1.getObj1();
		Box b2 = null;
		try {
			b2 = (Box) b1.clone();
			b2.setWidth(10);
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		System.out.println("b1 :"+b1.area());
		System.out.println("b2 :"+b2.area());
		
		System.out.println(obj == b2.getObj1());
	}

}

class Box implements Cloneable{
	private int height;
	private int width;
	
	private Object obj1;
	
	public Box(int height, int width, Object obj){
		this.height = height;
		this.width = width;
		obj1 = obj;
	}
	
	public int area(){
		return height*width;
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		//return super.clone();
		return new Box(height, width, new Object());
	}

	/**
	 * @return the height
	 */
	public int getHeight() {
		return height;
	}

	/**
	 * @param height the height to set
	 */
	public void setHeight(int height) {
		this.height = height;
	}

	/**
	 * @return the width
	 */
	public int getWidth() {
		return width;
	}

	/**
	 * @param width the width to set
	 */
	public void setWidth(int width) {
		this.width = width;
	}

	/**
	 * @return the obj1
	 */
	public Object getObj1() {
		return obj1;
	}

	/**
	 * @param obj1 the obj1 to set
	 */
	public void setObj1(Object obj1) {
		this.obj1 = obj1;
	}
	
	
	
}
